package javabasic.slipch.anagram;
import java.util.Scanner;
import java.util.ArrayList;
import java.util.List;
import java.util.Collections;

public final class Main {

	public static void main(String[] args) {
	
		if( isAnagram ( input() ) ){
			System.out.print("\nThe phrases are anagrams\n");
		} else {
			System.out.print("\nThe phrases are not anagrams\n");
		}
			
	}
	
	private static  List<Character> toArray(final String string) {
		List<Character> result = new  ArrayList<Character> ();
		for ( char ch : string.replaceAll("\\s", "").toLowerCase().toCharArray()) {
			result.add(ch);
		}
		Collections.sort(result);
		return result;	
	}
	
	private static boolean isAnagram( final String[] phrases) {
		return toArray(phrases[0]).equals(toArray(phrases[1]));
	}
	
	private static String[] input() {
		
		Scanner inputReader = new Scanner(System.in);
		String result[] = new String[2];
		System.out.print("\nEnter a phrase\n");
		result[0] = inputReader.nextLine();
		System.out.print("\nEnter another phrase\n");
		result[1] = inputReader.nextLine();

		return result;
	}
}
